<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Cetak OR</title>
<?php $this->load->helper('HTML');
echo link_tag('css/style2.css');
echo link_tag('images/favicon.ico','shortcut icon','image/x-icon');
?>
</head>
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=print_boom_omset_unit.xls");
header("Pragma: no-cache");
header("Expires: 0");

$max = 0;
	for($i=0;$i<sizeof($dataTemp);$i++){
		if($max < $dataTemp[$i]['intlevel_dealer']){
			$max = $dataTemp[$i]['intlevel_dealer'];
		}
	}
	
?>
<body>
<table border="1">
<tr>
	<td colspan="<?php echo $max+3;?>">Periode Boom <?php echo $tglawal." - ".$tglakhir?>  All Ranting</td>
</tr>
<?php
	//fungsi rekusif untuk cari omset unit
	function rekursifUnit($dataTemp,$cekDealer){
		$omsetUnit = 0;
		$omset = 0;
		$var = "";
		for($i = 0;$i<sizeof($dataTemp);$i++){
			if($dataTemp[$i]['strkode_upline'] == $cekDealer){
				$omset		=	$dataTemp[$i]['inttotal_omset'];
				$var	=	rekursifUnit($dataTemp,$dataTemp[$i]['strkode_dealer']);
				$omsetUnit	=	$var + $omsetUnit + $omset;
				}
			}
		return $omsetUnit;
		}
	echo "<tr>";
	echo "<th>Kode Dealer</th>";
	for($i=1;$i<=$max;$i++){
		echo "<th>Dealer level ".$i."</th>";
	}
	echo "<th>Omset</th>";
	echo "<th>Omset Unit</th>";
	echo "</tr>";
	$var =	array();
	$varTemp = "";
	for($i=0;$i<sizeof($dataTemp);$i++){
		//tampilin kesini
		$omsetUnit = 0;
		$omsetUnit = rekursifUnit($dataTemp,$dataTemp[$i]['strkode_dealer']);
		$omsetUnit = $dataTemp[$i]['inttotal_omset'] + $omsetUnit;
		if($omsetUnit != 0){
			 $varTemp = "<tr>";
			$varTemp .= "<td>".$dataTemp[$i]['strkode_dealer']."</td>";
			$var[0] = $dataTemp[$i]['intlevel_dealer'] - 1;
			$var[2] = $max - $dataTemp[$i]['intlevel_dealer'];
			if($var[0] != 0){
				$var[1] = $dataTemp[$i]['intlevel_dealer'];
				for($z=1;$z < $var[1];$z++){
					$varTemp .= "<td>&nbsp;</td>";
				}
				$varTemp .= "<td>".$dataTemp[$i]['strnama_dealer']."</td>";
				for($z=1;$z <= $var[2];$z++){
					$varTemp .= "<td>&nbsp;</td>";
				}
			}else{
				$varTemp .= "<td>".$dataTemp[$i]['strnama_dealer']."</td>";
				
				for($z=1;$z <= $var[2];$z++){
					$varTemp .= "<td>&nbsp;</td>";
				}
			}
			$varTemp .= "<td>".$dataTemp[$i]['inttotal_omset']."</td>";
			$varTemp .= "<td>".$omsetUnit."</td>";
			$varTemp .= "</tr>";
			echo $varTemp;
		}
	}
	
?>
</table>
</body>
</html>
